package com.groupbuying.store.utils;

import ch.hsr.geohash.GeoHash;
import com.groupbuying.store.constants.GeoHashConstants;
import com.spatial4j.core.io.GeohashUtils;

/**
 * @anthor wenguoqiang
 * @date: 2019/06/05 17:24
 * @company 够样
 * @des
 **/
public class GeoHashUtils {

    /**
     * @param lat       维度
     * @param lgt       经度
     * @param precision 经度
     * @return
     */
    public static String getGeoHash(Double lat, Double lgt, int precision) {
        return GeohashUtils.encodeLatLon(lat, lgt, precision);
    }

    public static String[] getAdjacent(Double lat, Double lgt, int precision) {
        GeoHash geoHash = GeoHash.withCharacterPrecision(lat, lgt, precision);
        GeoHash[] adjacent = geoHash.getAdjacent();
        String[] adjecentStr = new String[adjacent.length];
        for (int i = 0; i < adjacent.length; i++){
            System.out.println(adjacent[i].toBase32());
            adjecentStr[i]=adjacent[i].toBase32();
        }
        return adjecentStr;
    }



    public static void main(String[] args) {
        getAdjacent(39.98,116.31, GeoHashConstants.level6);
    }
}